class ActionMailer::Base
  @@default_url_options = {host: 'localhost', port: 9000, protocol: 'http'}

  def self.default_url_options
    @@default_url_options
  end

  def self.default_url_options=(hash)
    @@default_url_options.merge!(hash)
  end

  def url_for(path, query={}, url_options={})
    url_options.reverse_merge! self.class.default_url_options
    path.prepend('/') unless path.start_with?('/')
    protocol = url_options[:protocol]
    host = url_options[:host]
    port = url_options[:port]
    query_string = query.map{|k, v| "#{k}=#{v}"}.join('&')
    "#{protocol}://#{host}:#{port}#{path}?#{query_string}"
  end
end